﻿@model IEnumerable<CmsContentType>
           
@{
    ResFile = "cms_Content";
    Layout = "~/admin/Templates/TelerikAdministration.cshtml";
}

@{
    ViewBag.Title = _("Content types");
}

    <h1 class="g-clear">
        <i class="b-icon b-icon_h b-icon_h_contenttypes"></i>
	<span class="b-overflow">
		@_("Content type management")
		<span class="b-intro-text">@_("Content type management intro text will be here.")</span>
	</span>
    </h1>


<p class="clear-left">
    <a class="b-button" href="@Url.Action("add", "cmscontenttype")">@_("Add new content type")</a>
</p>
@{Html.RenderPartial("ErrorPanel");}
@(Html.Telerik().Grid(Model).Name("ContentTypeGrid")
        .Columns(columns =>
        {
            columns.Bound(p => p.ContentTypeName).Title(_("Content Type Name")).Template(
                @<text>
                <a href="@Url.Action("edit", "cmscontenttype", new { id = item.Id })">@item.ContentTypeName</a>
                </text>
            ).ClientTemplate("<a href=" + Url.Action("edit", "cmscontenttype") + "/<#= Id#>><#= ContentTypeName#></a>");
            columns.Bound(p => p.Description).Title(_("Description"));                        
            columns.Bound(p => p.DateCreated).Title(_("Date created")).Format("{0:dd/MM/yyyy}").ClientTemplate("<#= $.telerik.formatString('{0:dd/MM/yyyy}', DateCreated) #>");
            columns.Bound(p => p.UserCreatedBy).Title(_("Creator"));
            columns.Bound(p => p.Id);
            columns.Template(
                @<text>
                @if (!item.IsSystemType)
                {                    
                    <a class="b-icon b-icon_delete" data-confirm-message="@_("Are you sure you want to delete this content type and all its items?")" title="@_("Delete")" href="@Url.Action("delete", "cmscontenttype", new { id = item.Id })">@_("Delete")</a>
                }
                </text>
            )
            .ClientTemplate("<a id='contenttype-delete-<#= Id #>' class='b-icon b-icon_delete' title='" + _("Delete") + "' data-confirm-message=\"" + _("Are you sure you want to delete this content type and all its items?") + "\">" + _("Delete") + "</a>")
            .Title(_("Delete"));
        })
        .DataBinding(dataBinding =>
        {
            dataBinding.Ajax().Select("_index", "cmscontenttype");
        })
        .ClientEvents(events => events.OnRowDataBound("grid_onRowDataBound"))
        .Scrollable(scrolling => scrolling.Enabled(false))
        .Sortable(sorting => sorting.Enabled(true))
        .Pageable(paging => paging.Style(GridPagerStyles.Numeric).Total(ViewBag.Total).PageSize(ViewBag.PageSize).Enabled(ViewBag.Total > ViewBag.PageSize))
)
@{Html.RenderPartial("GridSizer", (int)ViewBag.PageSize);}

@section scriptBlock{
<script type="text/javascript">
// <![CDATA[    
    function grid_onRowDataBound(e) {
        var dataItem = e.dataItem
        var $el = $('#contenttype-delete-' + dataItem.Id);
        if ($el) {
            if (!dataItem.IsSystem) {
                $el.attr('href', '@Url.Action("delete", "cmscontenttype")' + "/" + dataItem.Id);
            }
            else {
                $el.hide().remove();
            }
        }
    }
    // ]]>
</script>
}